<?php

class AdminIdentity extends CUserIdentity
{
	private $_id;
	private $_shell;
	
	public function authenticate()
	{
		$username = strtolower($this->username);
		$user = Admin::model()->find('LOWER(admin_username)=?',array($username));
		if($user === NULL)
		{
			$this->errorCode = self::ERROR_USERNAME_INVALID;
		}else if(!$user->checkAdminPassword($this->password)){
			$this->errorCode = self::ERROR_PASSWORD_INVALID;
		}else{
			$this->_id = $user->admin_id;
			$this->_shell = $user->admin_shell;
			$this->username = $user->admin_username;
			$this->errorCode = self::ERROR_NONE;
		}
		return $this->errorCode;
	}
	
	public function getId(){
		return $this->_id;
	}
	
	public function getPersistentStates()
	{
		return array(
			'admin_shell'=>$this->_shell
		);
	}
}
